package com.code2roc.jarmanage.servlet.nginx;

import com.code2roc.jarmanage.db.ConfigDB;
import com.code2roc.jarmanage.model.ConfigDO;
import com.code2roc.jarmanage.model.Result;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

public class NginxHomeDetailServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Result result = Result.okResult();
        String nginxHome = "";
        boolean check = false;
        ConfigDO configDO =  ConfigDB.selectOne("NGINX_HOME");
        if (configDO != null) {
            nginxHome = configDO.getConfigValue();
            File file = new File(nginxHome);
            if(file.exists()){
                check = true;
            }
        }
        result.add("nginxHome",nginxHome);
        result.add("check",check);
        resp.getWriter().println(result.toString());
    }
}
